package com.manage.platform.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.manage.platform.dto.TaskTargetDto;
import com.manage.platform.entity.TaskTargetEntity;
import com.manage.platform.mapper.TaskTargetMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * YWD
 * 2025/9/25
 */
@AllArgsConstructor
@Service
public class TaskTargetServiceImpl extends ServiceImpl<TaskTargetMapper, TaskTargetEntity> {

    private final TaskTargetFileServiceImpl taskTargetFileServiceImpl;


    public TaskTargetDto saveTaskTarget(TaskTargetDto dto) {
        this.baseMapper.saveTaskTarget(dto);
        return dto;
    }


    public Boolean removeByTaskId(Long taskId) {
        LambdaQueryWrapper<TaskTargetEntity> queryWrapper = Wrappers.<TaskTargetEntity>lambdaQuery();
        queryWrapper.eq(TaskTargetEntity::getTaskId, taskId);
        List<TaskTargetEntity> list = list(queryWrapper);
        List<Long> list1 = list.stream().map(TaskTargetEntity::getId).toList();
        //删除目标值附件
        taskTargetFileServiceImpl.removeByTaskTargetId(list1);

        LambdaQueryWrapper<TaskTargetEntity> queryWrapper1 = new LambdaQueryWrapper<>();
        queryWrapper1.eq(TaskTargetEntity::getTaskId, taskId);
        return this.remove(queryWrapper1);
    }


}
